Ext.namespace('SLM');

SLM.EventsForm = function(config) {

	Ext.apply(this, config, {
			region: 'right'
		,	id: 'event_form'
		,	title: 'Search'
		,	labelWidth: 75
		,	collapsible: false
		,	split: true
		,	width: 300
		,	border: false
		,	bodyStyle: 'padding: 5px'
		,	defaultType: 'textfield'
		,	defaults: {
				anchor: '100%'
			}
		,	items: [{
						xtype: 'xtwincombo'
					, fieldLabel: 'Event Type'
					, name: 'event_type_id'
					,	queryParam: 'value'		
					,	store: new Ext.data.Store({
								proxy: new Ext.data.HttpProxy({url: Config.baseUrl + 'resources/api/app.php'})
							,	baseParams: { cmd: "eventtype-getlist", field: 'title' }
							, reader: new Ext.data.JsonReader({id: 'name', root: 'records'}, [ {name: 'name', mapping: 'value'}, 'event_type_id' ])
						})
					,	displayField: 'name'
					,	typeAhead: false
					, triggerAction: 'all'
					,	editable: false
					,	value:''
					,	valueField: 'event_type_id'
					, hiddenName: 'event_type_id'
					, listeners: {
								'select': this.filtersChanged.createDelegate( this )
							,	'clear': this.filtersChanged.createDelegate( this )
						}		
				}, {
						xtype: 'xtwincombo'
					, fieldLabel: 'Property'
					, name: 'land_id'
					,	queryParam: 'value'		
					,	store: new Ext.data.Store({
								proxy: new Ext.data.HttpProxy({url: Config.baseUrl + 'resources/api/app.php'})
							,	baseParams: { cmd: "land-getlist", field: 'title', showall: true }
							, reader: new Ext.data.JsonReader({id: 'name', root: 'records'}, [ {name: 'name', mapping: 'value'}, 'land_id' ])
						})
					,	displayField: 'name'
					,	typeAhead: false
					, triggerAction: 'all'
					,	editable: false
					,	value: ''
					,	valueField: 'land_id'
					, hiddenName: 'land_id'
					, listeners: {
								'select': this.filtersChanged.createDelegate( this )
							,	'clear': this.filtersChanged.createDelegate( this )
						}		
				}, {
						xtype: 'xtwincombodate'
					, 	fieldLabel: 'Event Start'
					, 	name: 'date_start'
					,	editable: false
					,	format: 'Y-m-d'
					, 	listeners: {
								select: function() { this.filtersChanged( this ); }
							,	clear: function() { this.filtersChanged( this );}
							,	scope: this
						}	
				}, {
						xtype: 'xtwincombodate'
					,	fieldLabel: 'Event End'
					, 	name: 'date_end'
					,	editable: false
					,	format: 'Y-m-d'
					, 	listeners: {
								select: function() { this.filtersChanged( this ); }
							,	clear: function() { this.filtersChanged( this );}
							,	scope: this
						}		
				}]			
		,	tbar: [{
					text: 'My Events'
				,	id: 'my_events'
				,	iconCls: 'icon_my'
				,	enableToggle: true
				,	listeners: {
						toggle: this.filtersChanged.createDelegate( this )
					}
			}, '->', {
					text: 'Reset Filters'
				, 	iconCls: 'x-tbar-loading'
				,	scope: this
				, 	handler: function() {
						this.filtersChanged();
						this.form.reset();
					}
			}]		
	});

	SLM.EventsForm.superclass.constructor.apply(this, arguments);

};

Ext.extend( SLM.EventsForm, Ext.FormPanel, {
	filtersChanged: function( btn, toggle ) {
		this.fireEvent('filtersChanged');
	}	
});